package net.starwifi.duobao.web.db;

import net.starwifi.duobao.entity.DBOrder;
import net.starwifi.duobao.entity.DBShare;
import net.starwifi.duobao.entity.Member;
import net.starwifi.duobao.mvc.*;
import net.starwifi.duobao.service.DBShareService;
import net.starwifi.duobao.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/24.
 */
@Controller("apiDBShareController")
@RequestMapping("/db")
public class DBShareController extends BaseController {


    @Autowired
    DBShareService dbShareService;

    @Autowired
    MemberService memberService;

    /**
     * 晒单列表
     */
    @RequestMapping(value = "/share", method = RequestMethod.GET)
    public String dbShareTip(Model model) {
        List<Order> orderBy=new ArrayList<Order>();
        orderBy.add(net.starwifi.duobao.mvc.Order.desc("id"));
        List<DBShare> dbTimesList=dbShareService.getListData(0,10,"o.isShow=?1",new Object[]{Boolean.TRUE},orderBy);
        model.addAttribute("dbShareList",dbTimesList);
        return "/db/share-list";
    }

    @RequestMapping(value = "/share-content", method = RequestMethod.GET)
    public String dbTimesRecordContent(Model model, int pageNum) {
        Member member = memberService.getCurrent();
        PageView pageView = new PageView(pageNum, 10);
        pageView.addOrder(net.starwifi.duobao.mvc.Order.desc("id"));
        pageView.addFilter(Filter.eq("isShow", Boolean.TRUE));
        //pageView.addFilter(Filter.eq("memberId", member.getId()));
        Page<DBShare> page = dbShareService.getScrollData(pageView);
        model.addAttribute("dbShareList",page.getContent());
        return "/db/share-content";
    }


    /**
     * 我的中奖详情信息
     */
    @RequestMapping(value = "/share-detail-{id}", method = RequestMethod.GET)
    public String dbShareDetail(Model model,@PathVariable Long id) {
        model.addAttribute("dbShare",dbShareService.find(id));
        return "/db/share-detail";
    }


}
